﻿using System.ServiceModel;
using FileManager_Client.BusinessLogic.FileTransferService;

namespace FileManager_Client.PresentationLayer.Common
{
    public class ServiceBroker
    {
         public static FileTransfer_ServiceClient CreateFileServer()
         {
             var fileTransferServiceClient = new FileTransfer_ServiceClient();
             if (fileTransferServiceClient.State != CommunicationState.Opened)
                 fileTransferServiceClient.Open();
             return fileTransferServiceClient;
         }

         public static void DisposeService(FileTransfer_ServiceClient channel)
         {
             if ((channel == null) || (channel.State == CommunicationState.Closed)) return;
             try
             {
                 if (channel.State != CommunicationState.Faulted)
                 {
                     channel.Close();
                 }
                 else
                 {
                     channel.Abort();
                 }
             }
             catch
             {
             }
         }
    }
}